/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import java.util.HashMap;


/**
 * - Helper class to send consistent, and more legible Responses back to Client.
 * 
 * @author BrandonNeal
 */
public class Response {

    
    public static enum FailCode{  //Enum of all the possible Fail messages
        FILE_NOT_FOUND,
        FILE_EXISTS,
        FILE_PERMISSIONS,
        FILE_LOCKED,
        USER_INVALID_LOGIN,
        USER_INVALID_REGISTER
    }
    private HashMap failures = new HashMap();
    
    
    public Response()
    {
        
        
        //Build list of FailCode => Fail Message
        failures.put(Response.FailCode.FILE_NOT_FOUND, "File does not exist");
        failures.put(Response.FailCode.FILE_EXISTS, "File with the same filename already exists");
        failures.put(Response.FailCode.FILE_PERMISSIONS, "You do not have permissions for this action");
        failures.put(Response.FailCode.FILE_LOCKED, "File is currently locked");
        failures.put(Response.FailCode.USER_INVALID_LOGIN, "Invalid username and password");
        failures.put(Response.FailCode.USER_INVALID_REGISTER, "Username already exists");
        
    }
    
    public String SuccessResponse()
    {
        return buildString(new String[]{"T"});
    }
    
    public String SuccessResponse(String Message)
    {
        return buildString(new String[]{"T",Message});
    }
        
    public String Response(String Message)
    {
        return buildString(new String[]{Message});
    }
    
    public String FailedResponse(FailCode fc)
    {
        return buildString(new String[]{"F",(String)failures.get(fc)});
    }
      
    public String ErrorResponse(String Message)
    {
        return buildString(new String[]{"ERROR",Message});
    }
    
    /**
     * Builds the Response string in the format that it is expected on Client side
     * @param message
     * @return 
     */
    public String buildString(String[] message)
    {
        String m="";
        
        for(String s:message)
        {
            m+=s+Server.SPLIT;
        }
        m+="\n";
        return m;
    }
}
